<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.name" placeholder="姓名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        width="150px"
        prop="name"
        header-align="center"
        align="center"
        label="司机姓名">
      </el-table-column>
      <el-table-column
        width="200px"
        prop="phone"
        header-align="center"
        align="center"
        label="手机号">
      </el-table-column>
      <el-table-column
        width="140px"
        prop="inAmount"
        header-align="center"
        align="center"
        label="预支总金额">
      </el-table-column>
      <el-table-column
        width="140px"
        prop="outAmount"
        header-align="center"
        align="center"
        label="报销总金额">
      </el-table-column>
      <el-table-column
        width="140px"
        prop="balance"
        header-align="center"
        align="center"
        label="预支结余">
      </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('tms:prepaybill:prepay')" type="text" size="small" @click="expenditureHandlen(scope.row.id)">预支</el-button>
          <el-button type="text" size="small" @click="detailHandle(scope.row.id)">明细</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <prepaybill v-if="prepaybill" ref="prepaybill" @refreshDataList="getDataList"></prepaybill>
    <prepay v-if="prepay" ref="prepay" @refreshDataList="getDataList"></prepay>
  </div>
</template>

<script>
  import prepaybill from './prepaybill'
  import prepay from './prepay'
  export default {
    data () {
      return {
        dataForm: {
          name: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        prepaybill: false,
        prepay:false
      }
    },
    components: {
      prepaybill,prepay
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/tms/driver/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'name': this.dataForm.name
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      detailHandle (id) {
        this.prepaybill = true
        this.$nextTick(() => {
          this.$refs.prepaybill.init(id)
        })
      },
      expenditureHandlen(id){
        this.prepay = true
        this.$nextTick(() => {
          this.$refs.prepay.init(id)
        })
      }
    }
  }
</script>
